package com.servlet;


import com.entity.User;
import com.service.LoginService;
import com.service.RegisterService;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import java.io.IOException;


public class UserController extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        HttpSession session=request.getSession();
        // 处理登录逻辑
        LoginService loginService = new LoginService();
        //获取所有登录数据
        String username=(String)request.getParameter("username");
        String password=(String)request.getParameter("password");
        String identity=(String)request.getParameter("identity");
        String phone = null;
        User user = new User(username,password,identity,phone);
        int f = 0;
        f = loginService.login(user);
        if(f == 0){
            String  text="用户名或密码错误";
            session.setAttribute("text", text);
            request.getRequestDispatcher("login.jsp").forward(request, response);
        }
        else{
            session.setAttribute("username", username);
            if(identity.equals("customer")){
                request.getRequestDispatcher("main.jsp").forward(request, response);
            }
            else if(identity.equals("merchant")){
                request.getRequestDispatcher("main_merchant.jsp").forward(request, response);
            }
            else{
                request.getRequestDispatcher("main_deliveryman.jsp").forward(request, response);
            }
        }
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    }
}

